package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.Dict;
import com.xmy.cultivate.mapper.DictMapper;
import com.xmy.cultivate.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author min
 * @since 2022-07-26
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {

    @Autowired
    DictMapper dictMapper;
    public Integer getMaxNumForType(Integer type){
        return dictMapper.getMaxNumForType(type);
    }

    public IPage<Dict> findAll(IPage<?> page, @Param(Constants.WRAPPER) Wrapper wrapper){
        return dictMapper.findAll(page,wrapper);
    }

    public List<Map<String,Object>> getList(@Param(Constants.WRAPPER) Wrapper wrapper){
        return dictMapper.getList(wrapper);
    }
    /**
     * 获取是否假期
     * @param num
     * @return
     */
    public Integer getIsVacation(Integer num){
        Dict dict = this.getQuarter(num);
        return dict.getTag();
    }
    /**
     * 获取学期
     * @param num
     * @return
     */
    public Dict getQuarter(Integer num){
        Integer type = 19;
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("num",num);
        dictQueryWrapper.eq("type",type);
        dictQueryWrapper.last("limit 1");
        return dictMapper.selectOne(dictQueryWrapper);
    }
}
